import requests

from com.yuhua.oa.utils.utils import oahost, faker


class Job():
    def queryJobList(self,token,pageNum=1,pageSize=10,postCode="",postName="",status=""):
        params = {
            "pageNum":pageNum,
            "pageSize":pageSize,
            "postCode":postCode,
            "postName":postName,
            "status":status
        }
        resp = requests.get(oahost + "/system/post/list", headers = token, params=params)
        return resp
    # 新增岗位
    def addJob(self,token):
        params = {
            "postCode": faker.postcode(),
            "postSort": 1,
            "postName": faker.name(),
            "status": "0"
        }
        resp = requests.post(oahost + "/system/post", headers=token,json=params)
        return resp

        # 修改岗位
    def updateJob(self, token):
        listResp = self.queryJobList(token, pageNum=1, pageSize=10)
        postId = listResp.json()["rows"][-1]["postId"]
        params = {
            "postId": postId,
            "postCode": faker.postcode(),
            "postSort": 1,
            "postName": faker.name(),
            "status": "0"
        }
        resp = requests.put(oahost + "/system/post", headers=token, json=params)
        return resp
    # 导出岗位列表
    def exportJob(self, token):
        params = {"pageNum": 1,"pageSize": 10}
        resp = requests.get(oahost + "/system/post/export", headers=token, params=params)
        return resp
    # 获取岗位选择框列表
    def optionselect(self, token):
        resp = requests.get(oahost + "/system/post/optionselect", headers=token)
        return resp
    # 删除岗位
    def deleteJob(self, token):
        listResp = self.queryJobList(token,pageNum=1,pageSize=10)
        postId = listResp.json()["rows"][-1]["postId"]
        resp = requests.delete(oahost + "/system/post/{}".format(postId), headers=token)
        return resp
    # 岗位详细信息
    def detailJob(self, token):
        listResp = self.queryJobList(token,pageNum=1,pageSize=10)
        postId = listResp.json()["rows"][-1]["postId"]
        resp = requests.get(oahost + "/system/post/{}".format(postId), headers=token)
        return resp